package com.worldwizards;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;

public class PlaytimeRecCellEditor extends AbstractCellEditor implements
		TableCellEditor,ActionListener {

	HeroPlaytimeRecord rec = null;
	JDialog editDialog;
	PlaytimeRecFieldEditor fieldEditor;
	JButton clickToEdit;
	JTable myTable;
	
	public PlaytimeRecCellEditor(){
		editDialog = new JDialog((JFrame)null,true);
		editDialog.setLayout(new BorderLayout());
		fieldEditor = new PlaytimeRecFieldEditor();
		editDialog.add(fieldEditor);
		editDialog.pack();
		clickToEdit = new JButton("Editing Flags");
		clickToEdit.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				//System.out.println("editing");
				int ret = JOptionPane.showConfirmDialog(null, fieldEditor,rec.name,
						JOptionPane.OK_CANCEL_OPTION);
				if (ret != JOptionPane.CANCEL_OPTION){
					fieldEditor.getRecord(rec);
				}
				myTable.editingStopped(new ChangeEvent(rec));
				
			}
			
		});
	}

	public Object getCellEditorValue() {
		return rec;
	}

	public Component getTableCellEditorComponent(JTable table,
            Object value,
            boolean isSelected,
            int row,
            int column) {
		myTable = table;
		rec = (HeroPlaytimeRecord) value;
		fieldEditor.setRecord(rec);
		return clickToEdit;
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
}
